#ifndef __NT35510_H__
#define __NT35510_H__

#include "fonts.h"
#include <stdbool.h>

#define NT35510_CMD_ADDR ( ( uint32_t ) 0x6C00007e )    //  Base data

/* Change this value below if you have multiple devices on FSMC interface
 * and you're not using A16 for NT35510, e.g:
 * 0x600000000 |  (0x1<<(16+1)) = 0x60020000;
 * And if it's A17, then 0x600000000 | (0x1<<(17+1)) = 0x60040000;
 */
#define NT35510_DATA_ADDR ( ( uint32_t ) 0x6C000080 )   //  LCD Register Select: A16

//  Basic functions to write data via 16-bit parallel interface (FSMC)
#define NT35510_WRITE_REG ( *(__IO uint16_t *) (NT35510_CMD_ADDR) )
#define NT35510_WRITE_DATA ( *(__IO uint16_t *) (NT35510_DATA_ADDR) )

/********************************************************
 * Pin Maps for LCD and STM32:
 * STM32        |       NT35510_LCD     |       Comment
 * FSMC_Dx     -->      DBx             |   (16 lines in total)
 * FSMC_NOE    -->      LCD_RD          |   Read
 * FSMC_NWE    -->      LCD_WR          |   Write
 * FSMC_NEx    -->      LCD_CS          |   Chip select
 * FSMC_Ax     -->      LCD_RS          |   Register select (NOT Reset!)
 * User defined reset pin  --> LCD_RST  |   Reset   (See below)
 ********************************************************/

//  Reset pin is still needed for reset purpose
#define NT35510_RES_Pin
#define NT35510_RES_GPIO_Port

#define NT35510_BL_Pin       GPIO_PIN_15
#define NT35510_BL_GPIO_Port GPIOB

//  Orientation params
#define NT35510_MADCTL_MY  0x80
#define NT35510_MADCTL_MX  0x40
#define NT35510_MADCTL_MV  0x20
#define NT35510_MADCTL_ML  0x10
#define NT35510_MADCTL_RGB 0x00
#define NT35510_MADCTL_BGR 0x08
#define NT35510_MADCTL_MH  0x04

/* Select a rotate direction for display */
#define NT35510_SET_ROTATION 0

// default orientation
#if NT35510_SET_ROTATION == 0
    #define NT35510_WIDTH  480
    #define NT35510_HEIGHT 800
    #define NT35510_ROTATION (NT35510_MADCTL_MX | NT35510_MADCTL_BGR)


// rotate right
#elif NT35510_SET_ROTATION == 1
    #define NT35510_WIDTH  320
    #define NT35510_HEIGHT 240
    #define NT35510_ROTATION (NT35510_MADCTL_MX | NT35510_MADCTL_MY | NT35510_MADCTL_MV | NT35510_MADCTL_BGR)


// rotate left
#elif NT35510_SET_ROTATION == 2
    #define NT35510_WIDTH  320
    #define NT35510_HEIGHT 240
    #define NT35510_ROTATION (NT35510_MADCTL_MV | NT35510_MADCTL_BGR)

// upside down
#elif NT35510_SET_ROTATION == 3
    #define NT35510_WIDTH  240
    #define NT35510_HEIGHT 320
    #define NT35510_ROTATION (NT35510_MADCTL_MY | NT35510_MADCTL_BGR)
#endif

/****************************/

// Color definitions
#define	NT35510_BLACK   0x0000
#define	NT35510_BLUE    0x001F
#define	NT35510_RED     0xF800
#define	NT35510_GREEN   0x07E0
#define NT35510_CYAN    0x07FF
#define NT35510_MAGENTA 0xF81F
#define NT35510_YELLOW  0xFFE0
#define NT35510_WHITE   0xFFFF



void NT35510_Init(void);
void NT35510_Bl(char cmd);
uint32_t NT35510_ReadPoint(uint16_t x,uint16_t y);
void NT35510_DisplayOn(void);
void NT35510_DisplayOff(void);
void NT35510_SetCursor(uint16_t Xpos, uint16_t Ypos);
void NT35510_Set_Window(uint16_t sx,uint16_t sy,uint16_t width,uint16_t height);
void NT35510_Clear(uint32_t color);

#endif // __NT35510_H__
